#include <iostream>
#include <queue>
using namespace std;

int main()
{
    int n;
    cin>>n;
    queue<string>people;
    for (int i=0;i<n;i++)
    {
        string s;
        cin>>s;
        if (s=="in")
        {
            string p;
            cin>>p;
            people.push(p);
        }
        else if (s=="out")
            people.pop();
        else if (s=="q")
        {
            if (people.empty())
                cout<<"NULL"<<endl;
            else
                cout<<people.front()<<endl;
        }
    }
}